//
//  VerificationApplyVC.m
//  KuWoCan
//
//  Created by hwd on 17/3/16.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "VerificationApplyVC.h"
#import "LabTextFieldCell.h"
#import "ApplyAcGoalCell.h"
#import "CargoCell.h"
#import "orderTotalCell.h"
#import "LabTxtViewCell.h"
#import "PhotoManageCell.h"
#import "NWSaleApplyRequest.h"

@interface VerificationApplyVC () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,copy) NSArray *constArr;

@end

@implementation VerificationApplyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *constStrArr = @[@[@"活动名称",@"促销产品"],@[@"活动目的"],@[@"促销目标",@"执行城市"],@[@"执行范围",@"执行时间"],@[@"内容及形式",@"需要物料",@"总费用",@"费效比率",@"支持/配合部门",@"经销商",@"销售额",@"申请人",@"上级"]];
    _constArr = constStrArr;
    
    _cargoArr = @[@"dd",@"dddd"];
    
    

    
    
    
    [self setUpUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)changeInfo
{
    
}

- (void)setUpUI
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"促销活动申请";
    
    //创建列表
    TPKeyboardAvoidingTableView *tabView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
    tabView.backgroundColor = KwGaryColor;
    tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tabView.estimatedRowHeight = 40.0;
    tabView.rowHeight = UITableViewAutomaticDimension;
    tabView.delegate = self;
    tabView.dataSource = self;
    [self.view addSubview:tabView];
    [tabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.right.equalTo(@0);
        make.bottom.equalTo(@-55);
    }];
    
    //创建底部按钮
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [confirmBtn setBackgroundColor:KwBlueColor];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmBtn setTitle:@"提交" forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = KwFont(16.0);
    [confirmBtn addTarget:self action:@selector(startPlaceAnOrder) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.layer.masksToBounds = YES;
    confirmBtn.cornerRadius = 5.0;
    [self.view addSubview:confirmBtn];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-5);
        make.top.equalTo(tabView.mas_bottom).offset(1);
        make.left.equalTo(@5);
        make.right.equalTo(@-5);
    }];
    
}


//开始下单
- (void)startPlaceAnOrder
{
    //    OrderCargoChooseVC *vc =[[OrderCargoChooseVC alloc] init];
    //    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark tableViewDelegate,DataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 7;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 5;
    }
    else if (section == 1 || section == 5 ||section == 6)
    {
        return 1;
    }
    else if (section == 4)
    {
        return 9;
    }
    else
    {
        return 2;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 0;
    }
    else
    {
        return 10;
    }
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headView = [UIView new];
    headView.backgroundColor = KwGaryColor;
    return headView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *labTextFieldCell_ID = @"LabTextFieldCell";
    static NSString *applyAcGoalCell_ID = @"ApplyAcGoalCell";
    static NSString *cargoCell_ID = @"CargoCell";
    static NSString *orderTotalCell_ID = @"orderTotalCell";
    static NSString *labTxtViewCell_ID = @"LabTxtViewCell";
    static NSString *photoManageCell_ID = @"PhotoManageCell";
    
    if (indexPath.section == 1)
    {
        ApplyAcGoalCell *cell = [tableView dequeueReusableCellWithIdentifier:applyAcGoalCell_ID];
        if (!cell)
        {
            cell = [[ApplyAcGoalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:applyAcGoalCell_ID];
        }
        return cell;
    }
    else if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            LabTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:labTextFieldCell_ID];
            if (!cell)
            {
                cell = [[LabTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:labTextFieldCell_ID];
            }
            NSArray *strArr = _constArr[indexPath.section];
            cell.constStr = strArr[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        else if (indexPath.row == 1)
        {
            //这一行为 酷我商城
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tempCell_Id"];
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tempCell_Id"];
                [self createCellUIWithCell:cell];
            }
            return cell;
        }
        else if(indexPath.row == _cargoArr.count+2)
        {
            //这一行为合计
            orderTotalCell *cell = [tableView dequeueReusableCellWithIdentifier:orderTotalCell_ID];
            if (!cell)
            {
                cell = [[orderTotalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:orderTotalCell_ID];
            }
            return cell;
        }
        else
        {
            //其余为商品展示
            CargoCell *cell = [tableView dequeueReusableCellWithIdentifier:cargoCell_ID];
            if (!cell)
            {
                cell = [[CargoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cargoCell_ID];
            }
            return cell;
        }
        
    }
    else if (indexPath.section == 4)
    {
        if (indexPath.row == 1)
        {
            LabTxtViewCell *cell = [tableView dequeueReusableCellWithIdentifier:labTxtViewCell_ID];
            if (!cell)
            {
                cell = [[LabTxtViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:labTxtViewCell_ID];
            }
            cell.constStr = @"需要物料";
            cell.txtStr = @"200ML 营养多";
            return cell;
        }
        else
        {
            LabTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:labTextFieldCell_ID];
            if (!cell)
            {
                cell = [[LabTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:labTextFieldCell_ID];
            }
            NSArray *strArr = _constArr[indexPath.section];
            cell.constStr = strArr[indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }
    else if (indexPath.section == 5 || indexPath.section == 6)
    {
        PhotoManageCell *cell;
        cell = [tableView dequeueReusableCellWithIdentifier:photoManageCell_ID];
        if (!cell)
        {
            cell = [[PhotoManageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:photoManageCell_ID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if (indexPath.section == 5)
        {
            cell.leftTitle = @"活动现场照片管理";
        }
        else
        {
            cell.leftTitle = @"票据照片管理";
        }
        return cell;
    }
    else
    {
        LabTextFieldCell *cell = [tableView dequeueReusableCellWithIdentifier:labTextFieldCell_ID];
        if (!cell)
        {
            cell = [[LabTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:labTextFieldCell_ID];
        }
        NSArray *strArr = _constArr[indexPath.section];
        cell.constStr = strArr[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//创建第一行酷我商城单元格
- (void)createCellUIWithCell:(UITableViewCell *)cell
{
    UIImageView *img = [UIImageView new];
    img.image = kImg(@"shangchen");
    [cell addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.top.equalTo(@10);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    UILabel *lab = [UILabel new];
    lab.text = @"酷我商城";
    lab.font = KwFont(14.0);
    [cell addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(img.mas_right).offset(10);
        make.height.equalTo(@14);
        make.top.equalTo(img.mas_top);
    }];
    
    UIImageView *img2 = [UIImageView new];
    img2.image = kImg(@"next");
    [cell addSubview:img2];
    [img2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-15);
        make.size.mas_equalTo(CGSizeMake(12, 15));
        make.top.equalTo(img.mas_top);
    }];
    
    UIView *lineView = [UIView new];
    lineView.backgroundColor = KwGaryColor;
    [cell addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(img.mas_bottom).offset(10);
        make.left.right.equalTo(@0);
        make.height.equalTo(@1.5);
        make.bottom.equalTo(@0);
    }];
}
@end
